//
//  imageV.m
//  爱鲜蜂(郭少乾)
//
//  Created by GuoDeJin on 2016/11/19.
//  Copyright © 2016年 GuoDeJin. All rights reserved.
//

#import "imageV.h"
#import "Masonry.h"
#import "NSAttributedString+DJAdditon.h"
@implementation imageV

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

//UI布局
- (void)setupUI{
    
    self.image = [UIImage imageNamed:@"v2_my_avatar_bg"];

    UIButton *btn = [[UIButton alloc]init];
    
    //图文混排
    [btn setAttributedTitle:[NSAttributedString cz_imageTextWithImage:[UIImage imageNamed:@"v2_my_avatar"] title:@"未登录" fontSize:18 titleColor:[UIColor blackColor] spacing:7] forState:UIControlStateNormal];
    
    
    self.PhoneNumButton = btn;
    
    //设置按钮的行数为0,让按钮上的文字自动换行
    btn.titleLabel.numberOfLines = 0;
    //设置按钮文字的对齐方式为居中对齐
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    //让按钮自适应大小
    [btn sizeToFit];
    
    [btn addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:btn];
    self.userInteractionEnabled = YES;
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.center.equalTo(self);
        
    }];
    
    
    UIButton *btn2 = [[UIButton alloc]init];
    
    [btn2 setImage:[UIImage imageNamed:@"v2_my_settings_icon"] forState:UIControlStateNormal];
    
    [self addSubview:btn2];
    
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.mas_top).offset(20);
        make.right.equalTo(self.mas_right).offset(-20);
        
    }];
    
    [btn2 addTarget:self action:@selector(setAction) forControlEvents:UIControlEventTouchUpInside];
    
    
}

#pragma mark - 我的头像的点击事件
- (void)clickButton:(UIButton *)btn{
    
    
    if ([self.delegate respondsToSelector:@selector(touXiangPush)]) {
        
        [self.delegate touXiangPush];
    }
    
}
#pragma mark - 设置按钮的点击事件
- (void)setAction{
    
    if ([self.delegate respondsToSelector:@selector(sheZhiPush)]) {
        
        [self.delegate sheZhiPush];
    }
    
    
}

- (void)setPhoneNum:(NSString *)phoneNum
{
    _phoneNum = phoneNum;
    
    [self.PhoneNumButton setAttributedTitle:[NSAttributedString cz_imageTextWithImage:[UIImage imageNamed:@"v2_my_avatar"] title:phoneNum fontSize:18 titleColor:[UIColor blackColor] spacing:7] forState:UIControlStateNormal];
    
}

@end
